package com.excilys.capicsoubank.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.excilys.capicsoubank.dao.AccountDao;
import com.excilys.capicsoubank.entities.Account;
import com.excilys.capicsoubank.entities.User;

/**
 * Dao pour les comptes utilisateurs.
 * 
 * @author Guillaume Lenoir
 * 
 */
@Repository
public class AccountDaoImpl extends GenericDaoImpl<Account> implements
		AccountDao {

	public AccountDaoImpl() {
		super(Account.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Account> getAccountsByUser(User user) {
		String query = "from Account where user=:user order by accountId";

		List<Account> accounts = getCurrentSession().createQuery(query)
				.setEntity("user", user).list();

		return accounts;
	}
}
